/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eSales.com.DAL;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Persistence;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author karamelka
 */
@Entity
@Table(name = "bids")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Bids.findAll", query = "SELECT b FROM Bids b"),
    @NamedQuery(name = "Bids.findBySId", query = "SELECT b FROM Bids b WHERE b.sId = :sId"),
    @NamedQuery(name = "Bids.findByUserName", query = "SELECT b FROM Bids b WHERE b.userName = :userName"),
    @NamedQuery(name = "Bids.findByLotId", query = "SELECT b FROM Bids b WHERE b.lotId = :lotId"),
    @NamedQuery(name = "Bids.findByBid", query = "SELECT b FROM Bids b WHERE b.bid = :bid")})
public class Bids implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "sId")
    private Integer sId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "userName")
    private String userName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "lotId")
    private int lotId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "bid")
    private int bid;

    public Bids() {
    }

    public Bids(Integer sId) {
        this.sId = sId;
    }

    public Bids(Integer sId, String userName, int lotId, int bid) {
        this.sId = sId;
        this.userName = userName;
        this.lotId = lotId;
        this.bid = bid;
    }

    public Integer getSId() {
        return sId;
    }

    public void setSId(Integer sId) {
        this.sId = sId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getLotId() {
        return lotId;
    }

    public void setLotId(int lotId) {
        this.lotId = lotId;
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sId != null ? sId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bids)) {
            return false;
        }
        Bids other = (Bids) object;
        if ((this.sId == null && other.sId != null) || (this.sId != null && !this.sId.equals(other.sId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "eSales.com.DAL.Bids[ sId=" + sId + " ]";
    }

    public void commit() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("eSalesPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.persist(this);
        em.getTransaction().commit();
        em.close();
        emf.close();
    }

}
